import { ActionTypes, RecommendProductAction } from "./recommendProductsActions"

interface RecommendProductState {
	productList: any[]
	loading: boolean
	error: string | null
}

const defaultState: RecommendProductState = {
	loading: true,
	error: null,
	productList: [],
}

const recommendProductsReducer = (state = defaultState, action: RecommendProductAction) => {
	switch (action.type) {
		case ActionTypes.FETCH_RECOMMEND_PRODUCTS_START:
			return {
				...state,
				loading: true,
			}
		case ActionTypes.FETCH_RECOMMEND_PRODUCTS_SUCCESS:
			return {
				...state,
				loading: false,
				error: action.payload,
			}
		case ActionTypes.FETCH_RECOMMEND_PRODUCTS_FAILED:
			return state
		default:
			return state
	}
}

export default recommendProductsReducer
